﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm_2.Easy_441_ArrangeCoins
{
    class MainProject
    {
        static void Main(string[] args)
        {
            //int[] intArray1 = new int[] { 4, 9, 5 };
            //2147483647
            Console.WriteLine(ArrangeCoins(3));
            Console.ReadKey();
        }

        public static int ArrangeCoins(int n)
        {
            long remain = n;
            long longN = n;
            for (int i = 1; i <= longN + 1; i++)
            {
                if (remain < i)
                {
                    return Math.Max(i - 1, 0);
                }
                else
                {
                    remain = remain - i;
                }
            }
            return 0;
        }
    }
}
